package info.sixcorners.thesixcornersapp.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;

public class ErrorPanel {
	static final DialogBox errBox = new DialogBox();
	static final CheckBox submitErrsChkbx = new CheckBox("Submit errors");
	static final CheckBox saveErrsChkbx = new CheckBox("Save errors");
	static final Button errBoxCloseBtn = new Button("Close");
	static final Label errLabel = new Label();
	{
		errBox.addStyleName("errBox");
		errBox.setText("Error");
		errBox.setAnimationEnabled(true);
		errBoxCloseBtn.addStyleName("errBoxCloseBtn");
		errLabel.addStyleName("errLabel");
	}
	
	/**
	 * Sets up the error DialogBox's content.
	 */
	ErrorPanel() {
		final VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.setWidth("100%");
		dialogVPanel.add(errLabel);
		final HorizontalPanel bottomPanel = new HorizontalPanel();
		final VerticalPanel settingsVPanel = new VerticalPanel();
		settingsVPanel.addStyleName("settingsVPanel");
		settingsVPanel.add(submitErrsChkbx);
		settingsVPanel.add(saveErrsChkbx);
		bottomPanel.add(settingsVPanel);
		bottomPanel.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
		bottomPanel.add(errBoxCloseBtn);
		dialogVPanel.add(bottomPanel);
		errBox.setWidget(dialogVPanel);
		
		errBoxCloseBtn.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				errBox.hide();
			}
		});
	}
	
	static void error(String error) {
		errLabel.setText(error);
		errBox.center();
		errBoxCloseBtn.setFocus(true);
	}
}
